package com.qf.java2201.utils;


import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @ClassName : MD5Util
 * @Author : glls
 * @Date: 2021/7/22 9:18
 * @Description :
 */
public class MD5Util {

    // 加密方法
    public static String encodePwdByMD5(String str){
        try {
            MessageDigest messageDigest =  MessageDigest.getInstance("MD5");
            BASE64Encoder base64Encoder = new BASE64Encoder();
            return base64Encoder.encode(messageDigest.digest(str.getBytes("utf-8")));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String s = MD5Util.encodePwdByMD5("123456");
        System.out.println(s);
    }
}
